package cn.com.dashihui.api.service;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import cn.com.dashihui.api.base.BaseService;
import cn.com.dashihui.api.dao.Ad;
import cn.com.dashihui.api.dao.StoreAd;

public class AdService extends BaseService{
	
	/**
	 * 查询公共广告位
	 */
	public List<Ad> findPublicAd(){
		return Ad.me().find("SELECT id,thumb,link,1 type,null goodsid FROM t_bus_ad ORDER BY orderNo");
	}
	
	/**
	 * 查询指定店铺的广告位（只显示在APP显示的）<br/>
	 * 注：goodsid值暂时更名为id，下一版需要删除或更正，2016-03-04
	 */
	public List<StoreAd> findStoreAd(int storeid){
		return StoreAd.me().find("SELECT goodsid id,thumb,link,type,goodsid FROM t_bus_store_ad WHERE storeid=? AND isShowOnAPP=1 ORDER BY orderNo",storeid);
	}
	/**
	 * 查询服务信息列表
	 * @return
	 */
	public List<Record> queryServiceNews() {
		return Db.find("select * from t_wx_article where isTop =1 order by createDate DESC");
	}
	/**
	 * 查询系统信息列表
	 * @return
	 */
	public List<Record> querySystemNews(int type) {
		return Db.find("select * from t_web_notice where `show`=1 and type=? order by id DESC",type);
	}
	/**
	 * 查询公告信息详情
	 * @param id
	 * @return
	 */
	public Record querySystemNewsDeatil(int id) {
		return Db.findFirst("select * from t_web_notice where id=?",id);
	}
	
	/**
	 * 查询轮播图
	 * @param page
	 * @return
	 */
	public List<Record> queryCarousel(int page) {
		if (page==1) {
			return Db.find("select * from t_bus_ad order by orderNo");
		}else {
			return Db.find("select tb.*,ts.id as sid from t_bus_goods_base_baby tb LEFT JOIN t_bus_ege_goods_spec ts ON tb.goodsid=ts.goodId WHERE tb.isShow=1  GROUP BY tb.id order by tb.orderNo");
		} 
	}
}
